import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Home from '../views/index.vue'

import test from '../views/test.vue'
import stores from '@/store'

import Register from '../views/login/register.vue'
import Login from '../views/login/login.vue'
import LoginEmail from '../views/login/loginEmail.vue'

import function1 from '../views/areahot/areaHot.vue'
import function2 from '../views/areahot/totalHot.vue'
import function3 from '../views/areahot/guessHot.vue'
import function4 from '../views/anchor/anchorCount.vue'
import function5 from '../views/anchor/totalCount.vue'
import function6 from '../views/anchor/guessAnchor.vue'

import areaOnlineGame from '../views/wordCloud/area/onlineGame.vue'
import areaSingleGame from '../views/wordCloud/area/singleGame.vue'
import areaFunGame from '../views/wordCloud/area/funGame.vue'
import areaMobileGame from '../views/wordCloud/area/mobileGame.vue'
import areaWordCloud from '../views/wordCloud/area/areaWordCloud.vue'

import anchorOnlineGame from '../views/wordCloud/anchor/onlineGame.vue'
import anchorSingleGame from '../views/wordCloud/anchor/singleGame.vue'
import anchorFunGame from '../views/wordCloud/anchor/funGame.vue'
import anchorMobileGame from '../views/wordCloud/anchor/mobileGame.vue'
import anchorWordCloud from '../views/wordCloud/anchor/anchorWordCloud.vue'
import function9 from '../views/wordCloud/area/all.vue'
import function10 from '../views/wordCloud/anchor/all.vue'

import function11 from '../views/pieChart/LOLHero.vue'
import function12 from '../views/pieChart/blueRay.vue'
import function13 from '../views/top10/anchor.vue'
import function14 from '../views/top10/consume.vue'
import function15 from '../views/top10/fans.vue'
import function16 from '../views/others/function16.vue'
import function17 from '../views/others/function17.vue'
import function18 from '../views/others/function18.vue'
import function19 from '../views/others/function19.vue'
import function20 from '../views/others/function20.vue'

Vue.use(Router)

const router = new Router({
    routes: [{
        path: '/test',

        component: test
    }, {
        path: '/',
        redirect: '/login',
        component: Login
    }, {
        path: '/register',
        name: 'Register',
        component: Register
    }, {
        path: '/login',
        name: 'Login',
        component: Login
    }, {
        path: '/loginEmail',
        name: 'LoginEmail',
        component: LoginEmail
    }, {
        path: '/home',
        name: 'Home',
        redirect: '/home/function1',
        component: Home,
        children: [{
                path: '/',
                redirect: 'function1',
                component: function1
            }, {
                path: 'function1',
                component: function1
            }, {
                path: 'function2',
                component: function2
            }, {
                path: 'function3',
                component: function3
            }, {
                path: 'function4',
                component: function4
            }, {
                path: 'function5',
                component: function5
            }, {
                path: 'function6',
                component: function6
            },

            {
                path: 'area/onlineGame',
                component: areaOnlineGame
            }, {
                path: 'area/singleGame',
                component: areaSingleGame
            }, {
                path: 'area/funGame',
                component: areaFunGame
            }, {
                path: 'area/mobileGame',
                component: areaMobileGame
            },
            {
                path: 'area/areaWordCloud',
                component: areaWordCloud
            },

            {
                path: 'anchor/onlineGame',
                component: anchorOnlineGame
            }, {
                path: 'anchor/singleGame',
                component: anchorSingleGame
            }, {
                path: 'anchor/funGame',
                component: anchorFunGame
            }, {
                path: 'anchor/mobileGame',
                component: anchorMobileGame
            },
            {
                path: 'anchor/anchorWordCloud',
                component: anchorWordCloud
            },


            {
                path: 'function9',
                component: function9
            }, {
                path: 'function10',
                component: function10
            }, {
                path: 'function11',
                component: function11
            }, {
                path: 'function12',
                component: function12
            }, {
                path: 'function13',
                component: function13
            }, {
                path: 'function14',
                component: function14
            }, {
                path: 'function15',
                component: function15
            }, {
                path: 'function16',
                component: function16
            }, {
                path: 'function17',
                component: function17
            }, {
                path: 'function18',
                component: function18
            }, {
                path: 'function19',
                component: function19
            }, {
                path: 'function20',
                component: function20
            }
        ]
    }],
    mode: 'history'
})

router.beforeEach((to, from, next) => {
    //to将要访问的路径
    //from从哪个路径跳转
    //next()放行   , next('/login')强制跳转
    if (to.path === '/login') return next();
    else if (to.path === '/loginEmail') return next();
    else if (to.path === '/register') return next();
    //判断是否已经登陆，不是的话强制登录
    let id = window.sessionStorage.getItem('id');
    if (!id || id == '') {
        return next('/login');
    }
    next();

})


export default router